package com.lwj.liwanjia.adapter;

import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;
import android.widget.Toast;

import com.lwj.liwanjia.R;
import com.lwj.liwanjia.bean.MarketFDBean;
import com.lwj.liwanjia.config.OnItemClickListener;
import com.lwj.liwanjia.utils.MyGridView;
import com.lwj.liwanjia.view.activity.supermarket.ShangPinActivity;

import java.util.List;

/**
 * 右侧菜单
 */

public class MainSectionedAdapter extends SectionedBaseAdapter {
    private Context mContext;
    private List<MarketFDBean.DataBean> list;
    private OnItemClickListener listener;

    public void setListener(OnItemClickListener listener) {
        this.listener = listener;
    }

    public MainSectionedAdapter(Context context, List<MarketFDBean.DataBean> list) {
        this.mContext = context;
        this.list = list;
    }


    @Override
    public Object getItem(int section, int position) {
        return list.get(section).getGoodsType().get(position);
    }

    @Override
    public long getItemId(int section, int position) {
        return position;
    }

    //分类的个数
    @Override
    public int getSectionCount() {
        return list.size();
    }

    //每个分类中item项的长度
    @Override
    public int getCountForSection(int section) {
        //return rightStr[section].length;
        return 1;
    }

    @Override
    public View getItemView(final int section, final int position, View convertView, ViewGroup parent) {
        RelativeLayout layout = null;
        if (convertView == null) {
            LayoutInflater inflator = (LayoutInflater) parent.getContext()
                    .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
            layout = (RelativeLayout) inflator.inflate(R.layout.right_list_item, null);
            layout.setTag(1);
        } else {
            layout = (RelativeLayout) convertView;
        }
        MyGridView gridView = (MyGridView) layout.findViewById(R.id.my_gridview);
        MyGridAdapter myGridAdapter = new MyGridAdapter(mContext, list, section);
        gridView.setAdapter(myGridAdapter);
        listener.OnItemClick(gridView, section);
        return layout;
    }

    @Override
    public View getSectionHeaderView(int section, View convertView, ViewGroup parent) {
        LinearLayout layout = null;
        if (convertView == null) {
            LayoutInflater inflator = (LayoutInflater) parent.getContext()
                    .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
            layout = (LinearLayout) inflator.inflate(R.layout.right_header_item, null);
        } else {
            layout = (LinearLayout) convertView;
        }
        layout.setClickable(false);
        ((TextView) layout.findViewById(R.id.textItem)).setText(list.get(section).getCommondityType());
        return layout;
    }

}
